<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePostsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title',20);
            $table->mediumText('content');
            $table->string('source',20)->comment('来源');
            $table->json('assets')->comment('资源：可以是视频/文件/图片');
            $table->json('params')->comment('其他参数');
            $table->json('tag')->comment('标签');
            $table->unsignedTinyInteger('type')->comment('类型1:纯文');
            $table->integer('view')->default(0)->comment('浏览量');
            $table->integer('sort')->default(0)->comment('排序/权重');
            $table->boolean('top')->default(0)->comment('置顶/推荐');
            $table->integer('state')->default(0)->comment('状态');
            $table->unsignedInteger('user_id')->comment('关联的用户ID');
            $table->foreign('user_id')->references('id')->on('users');
            $table->unsignedInteger('admin_id')->comment('关联的管理ID');
            $table->foreign('admin_id')->references('id')->on('admins');
            $table->unsignedInteger('menu_id')->comment('关联的菜单ID');
            $table->foreign('menu_id')->references('id')->on('menus');

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('posts');
    }
}
